<?php
header("Content-Type: text/xml;charset=iso-8859-1");
require_once( './includes/WebStart.php' );

//this is the normal header applied to any Google sitemap.xml file 
echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; 



//if ( strpos($_SERVER['HTTP_USER_AGENT'],'Googlebot')!==false) {
//just generate the sitemap if you are a bot, dont waste resources

  
  
  $dbr = wfGetDB( DB_SLAVE );
  $sql = "SELECT SQL_CACHE COUNT(IdFile) as files FROM ss_tags";             
  $resql = $dbr->query( $sql );
	 
    
	$row = $dbr->fetchObject( $resql );
	//var_dump($row);
	
	//$wgOut .= $row;
	$numtot = $row->files;
	
	$dbr->freeResult( $resql );
  
  
  
  $numero = rand(1,$numtot);
  
  if ($numero >= 10001) {
   
  	$numero = $numero - 10000;
  
  }
  //$numero = mysql_real_escape_string($_GET['num']);
  $datenow = date("Y-m-d", time() );

  //echo $numero;
  //die();

   

    $dbr = wfGetDB( DB_SLAVE );
    $sql = "SELECT ArtistKey, TitleKey FROM ss_tags LIMIT 1000 OFFSET {$numero}";
    //google sitemaps limit 50000 
    
    
    $res = $dbr->query( $sql );
       
       
        while ($row = $dbr->fetchRow( $res )) {
       
	    //var_dump($row);
    
	    $out .= '<url>';
	    $out .= '<loc><![CDATA[ http://soundshare.com/download/'.$row[ArtistKey].'/'.$row[TitleKey].']]></loc>';
	    $out .='<lastmod>'.$datenow.'</lastmod> 
		<changefreq>daily</changefreq> 
		<priority>0.5</priority> 
		</url>';
       
         }//end of while
         
         
         
         $out .= '</urlset>';
         
         echo $out;
    
     $dbr->freeResult ( $res );
    
/* 
}else{
echo 'sitemaps are not for humans';
}*/